package models

import (
	"context"
	"go-chain-api/global"
	"go.mongodb.org/mongo-driver/bson"
)

type ChainToken struct {
	Id            string `bson:"_id,omitempty" json:"id"`
	Address       string `bson:"address" json:"address"`
	Name          string `bson:"name" json:"name"`
	Symbol        string `bson:"symbol" json:"symbol"`
	Decimals      uint   `bson:"decimals" json:"decimals"`
	ChainConfigId string `bson:"chainConfigId" json:"chainConfigId"`
}

func (c *ChainToken) List(ChainConfigId string) ([]ChainToken, error) {
	//model := new(ChainToken)
	//model.ChainConfigId = ChainConfigId
	var chainTokenList []ChainToken
	applyClient := global.DBEngine.Database(global.DbConfig.DbName).Collection("chain_token")
	find, err := applyClient.Find(context.TODO(), bson.M{"chainConfigId": ChainConfigId})
	if err != nil {
		return nil, err
	}
	err = find.All(context.TODO(), &chainTokenList)
	if err != nil {
		return nil, err
	}

	return chainTokenList, err
}
